//app.js
import { my_request, my_showToast_error } from './utils/my_utils'

App({
  data: {
    global_func: {},
    callScanCode: false,
    meetingSalt: 'QCBMEETINGID@2017BETA=',
  },
  getUpToken: function (cb) {
    var that = this,
      end = 1,
      time = new Date();

    time = Math.ceil(time.getTime() / 1000);
    if (!this.globalData.upToken) this.globalData.upToken = wx.getStorageSync('upToken') || '';
    if (this.globalData.upToken) {
      if (this.globalData.upToken.time > time) {
        end = 0;
        typeof cb == "function" && cb(this.globalData.upToken.token)
      }
    }
    if (end) {
      wx.request({
        url: 'https://sichuangyi.demopp.in/qiniu.php',
        method: 'GET',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          var upToken = {
            token: "",
            time: ""
          };
          upToken.token = res.data;
          upToken.time = time + 3500;
          that.globalData.upToken = upToken;
          wx.setStorageSync('upToken', upToken);
          typeof cb == "function" && cb(upToken.token)
        },
        fail: function (res) {
          console.log(res)
        }
      })
    }
  },
  globalData: {
    userInfo: null,
    upToken: null
  }
})